package nz.ac.massey.cs.stats.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;


public class GroupedData {
	private Map<String, LinkedList<List<Double>>> data;
	private Map<String, Character> symbols;
	public GroupedData() {
		data = new HashMap<String, LinkedList<List<Double>>>(); 
		symbols = new HashMap<String, Character>();
	}
	
	@SuppressWarnings("unchecked")
	public void add(String group, double x,double y){
		if(!data.containsKey(group)) {
			data.put(group, 
				new LinkedList<List<Double>>(Arrays.asList(
					new ArrayList<Double>(),	//xs
					new ArrayList<Double>()		//ys
				))
			);
			symbols.put(group, group.charAt(0));
		}
		data.get(group).getFirst().add(x);
		data.get(group).getLast().add(y);
	}

	public List<Double> getXs(String group){
		return Collections.unmodifiableList(data.get(group).getFirst());
	}
	
	public List<Double> getYs(String group){
		return Collections.unmodifiableList(data.get(group).getLast());
	}
	
	public Set<String> getGroups(){
		return Collections.unmodifiableSet(new TreeSet<String>(this.data.keySet()));
	}
	
	public void setSymbol(String group, char c){
		symbols.put(group, c);
	}
	
	public Character getSymbol(String group){
		return this.symbols.get(group);
	}
}
